package com.example.kabaouser.repository;

import com.example.kabaouser.dataobject.KabaoUser;
import org.apache.ibatis.annotations.*;

@Mapper
public interface KabaoUserRepository {

    @Select("select uid,username,password,phone" +
            ",token,timeout,status,create_time as createTime,update_time as updateTime from kabao_user where token = #{token}")
    public KabaoUser findUserByToken(String token);

    @Insert("insert into kabao_user(username,phone,token,timeout,create_time,update_time) " +
            "values(#{username},#{phone},#{token},#{timeout},#{createTime},#{updateTime})")
    @Options(useGeneratedKeys=true,keyProperty="uid",keyColumn = "uid")
    public void save(KabaoUser kabaoUser);

    @Select("select * from kabao_user where phone = #{phone}")
    public KabaoUser finUserByPhone(String phone);

    @Update("update kabao_user set token=#{token},timeout=#{timeout},update_time=#{updateTime} " +
            "where phone=#{phone}")
    public boolean updateKaBaoUser(KabaoUser kabaoUser);
}
